package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/nursing_project")
@Api(value = "护理项目",tags = "护理项目")
public class NursingProjectController extends BaseController{
    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation("分页查询护理项目")
    public ResponseResult<PageResponse<NursingProjectVo>> list(@ApiParam(value = "护理项目名称", required = false) String name,
                                                                                        @ApiParam(value = "当前页", defaultValue = "1") Integer pageNum,
                                                                                        @ApiParam(value = "每页显示记录数", defaultValue = "10") Integer pageSize,
                                                                                        @ApiParam(value = "状态", required = false) Byte status){
        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.list(name, pageNum, pageSize, status);

        return success(pageResponse);
    }

    /**
     * 新增
     */

    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult save(@RequestBody NursingProjectDto dto){
        nursingProjectService.save(dto);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询")
    public ResponseResult<NursingProjectVo> queryById(@PathVariable Long id){
        NursingProjectVo vo =  nursingProjectService.queryById(id);
        return success(vo);
    }

    @PutMapping
    @ApiOperation("根据id更新")
    public ResponseResult update(@RequestBody NursingProjectDto dto){
        nursingProjectService.update(dto);
        return success();
    }
}
